'use strict';
const db = uniCloud.database();
const collection = db.collection('houselist')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	
	const {pageNum, pageSize} = event
	// pageSize: 10, pageNum: 1,2,3
	// 1: 0-9  => pageNum - 1  + 10
	// 2: 10 - 19 => (pageNum - 1) * 10  + 10
	// 3: 20-29 => (pageNum - 1) * 10 + 10
	
	const start = (pageNum - 1) * 10
	console.log(start)
	// 从数据库houselist表中读数据
	const {data} = await collection.skip(start).limit(pageSize).get()
	const {total} = await collection.count()
	//返回数据给客户端
	return {
		data,
		total
	}
};
